package com.wandian.cqcsk.adapter.mine;


import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ledong.lib.leto.Leto;
import com.mgc.leto.game.base.MgcAccountManager;
import com.mgc.leto.game.base.bean.LoginResultBean;
import com.mgc.leto.game.base.listener.SyncUserInfoListener;
import com.mylib.libcore.AppContext;
import com.mylib.libcore.bean.EveryDayConfigBean;
import com.mylib.libcore.bean.UserInfoBean;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.cqcsk.R;
import com.wandian.cqcsk.bean.MineServiceItem;

/**
 * 我的-适配器
 */
public class MineRecycleAdapter extends BaseQuickAdapter<MineServiceItem, BaseViewHolder> {
    private  UserInfoBean userInfoBean = null;
    public MineRecycleAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, MineServiceItem item) {
        ImageView iv_mine_grid = helper.getView(R.id.iv_mine_grid);
        iv_mine_grid.setImageResource(item.getPicId());
        helper.setText(R.id.tv_mine_grid, item.getTitle()+"");
        RelativeLayout rl_item = helper.getView(R.id.rl_item);
        rl_item.setOnClickListener(v -> clinkByTitle(mContext,item.getTitle()+""));
        ImageView iv_mine_hot = helper.getView(R.id.iv_mine_hot);
        if(item.getTitle().equals("排名奖励") || item.getTitle().equals("战力挑战")){
            iv_mine_hot.setVisibility(View.VISIBLE);
        }else  iv_mine_hot.setVisibility(View.GONE);
    }

    private void clinkByTitle(Context context,String title){
        Bundle bundle = new Bundle();
        if(userInfoBean == null)userInfoBean=AppContext.getInstance().getAppPreferencesHelper().getUserInfoBean();
        switch (title){
            case "我的钱包":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_MY_WALLET).navigation();
                break;
            case "每日英语":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_EVERYDAY_ENGLISH).navigation();
                break;
            case "战力挑战":
                userInfoBean = AppContext.getInstance().getAppPreferencesHelper().getUserInfoBean();
                EveryDayConfigBean everyDayConfigBean = AppContext.getInstance().getAppPreferencesHelper().getEveryDayConfig();
                bundle.putString("zl_num",userInfoBean.getFightNum()+"");
                bundle.putString("zl_times",everyDayConfigBean.getFightNum()+"");
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_CHALLENGE).with(bundle).navigation();
                break;
            case "排名奖励":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_RANK).navigation();
                break;
            case "地图天气":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_MAP_WEATHER).navigation();
                break;
            case "邀请有奖":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_INVITE_REWARD).navigation();
                break;
            case "生活百科":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_LIFE_TOOL).navigation();
                break;
            case "知识宝库":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_KNOWLEDGE).navigation();
                break;
            case "休闲一会":
                //小游戏启动游戏中心
                MgcAccountManager.syncAccount(context,
                        userInfoBean.getId()+"", "",
                        userInfoBean.getNickName()+"",
                        userInfoBean.getHeadPic()+"", true,  new SyncUserInfoListener() {
                            @Override
                            public void onSuccess(LoginResultBean data) {
                                Log.d("MgcAccountManager","onSuccess");
                            }

                            @Override
                            public void onFail(String code, String message) {
                                Log.d("MgcAccountManager","onFail");
                            }
                        });
                Leto.getInstance().startGameCenter (context);
                break;
            case "小说天地":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_GAMES_BOOK).navigation();
                break;
            case "微文精选":
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_WX_TOP).navigation();
                break;
            case "闯关问答":
                EveryDayConfigBean everyDayConfigBean2 = AppContext.getInstance().getAppPreferencesHelper().getEveryDayConfig();
                bundle.putString("cg_num",userInfoBean.getEmigratedNum()+"");
                bundle.putString("cg_times",everyDayConfigBean2.getEmigratedNum()+"");
                ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_PASS_THROUGH).with(bundle).navigation();
                break;
        }
    }


}
